package com.smarthospital.web.controller;

import com.smarthospital.common.Result.ResultDTO;
import com.smarthospital.entity.im.IMMessage;
import com.smarthospital.service.IMMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;

/**
 * create by sym  2020/8/16 16:00.
 */
@RestController
@Slf4j
@RequestMapping("/mesage")
@Api(tags = "消息接口")
public class MessageController {

    @Autowired
    private IMMessageService messageService;

    @GetMapping("/list")
    @ApiOperation(value = "消息列表",
            notes =" 消息列表，分页查询\n " +
                    "param: orderId -> 订单id\n" +
                    "       pageSize -> 页码大小\n" +
                    "       pageNum -> 当前页数" )
    public ResultDTO list(@RequestParam("orderId")String orderId,@RequestHeader("SH_TOKEN")String SH_TOKEN,
                           @RequestParam("pageSize")Integer pageSize, @RequestParam("pageNum")Integer pageNum) throws ParseException {
        log.info("list orderId {}  pageSize {} pageNum {}",orderId,pageSize,pageNum );
        Page<IMMessage> messages = messageService.list(orderId,pageSize,pageNum);
        return ResultDTO.sucess(messages);
    }

    @GetMapping("/deleteAll")
    @ApiOperation(value = "清除消息记录",
            notes =" 清除消息记录" )
    public ResultDTO deleteAll(@RequestHeader("SH_TOKEN")String SH_TOKEN)  {
        messageService.deleteAll();
        return ResultDTO.sucess();
    }




}
